<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Home</title>
    <link href="assets/css/lib/themify-icons.css" rel="stylesheet">
    <link href="assets/css/lib/menubar/sidebar.css" rel="stylesheet">
    <link href="assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet" />
    <script src="js/jquery.min.js"></script>
    <script src="js/layer-v3.1.1/layer/layer.js"></script>
    <script src="js/demo.js"></script>
	<script src="assets/js/lib/jquery.nanoscroller.min.js"></script>
	<script src="assets/js/lib/menubar/sidebar.js"></script>
	<script src="assets/js/lib/preloader/pace.min.js"></script>
	<script src="assets/js/lib/bootstrap.min.js"></script>
	<script src="assets/js/lib/circle-progress/circle-progress.min.js"></script>
	<script src="assets/js/lib/circle-progress/circle-progress-init.js"></script>
</head>
<script src="assets/js/lib/jquery.min.js"></script>
<script type="text/javascript">
var userdelete = function (){
	var ID=$("#ID").val();
	var keyword=$.trim($("#key").val());
	$.ajax({
		type: 'POST',
		url: '<%=request.getContextPath() %>/UserDelete?userid="'+ID+'"',
		dataType: 'json',
		data: {},
		contentType: 'application/json;charset=UTF-8',
		success: function(e) {
			if (e.status === "COMMITTED") {
			}
			window.location="<%=request.getContextPath() %>/manage/allUser.jsp";
		},
	error: function(XMLHttpRequest, textStatus, errorThrown) {
    },
	});
}
var cancel=function(){
	layer.close(index);
	$("#deleteBox").css("display","none");
}
var usermodify = function (){
	var userid=$.trim($("#InputUserid").val());
    var username=$.trim($("#InputUsername").val());
    var pwd=$.trim($("#InputUserPwd").val());
	$.ajax({
		type: 'POST',
		url: '<%=request.getContextPath() %>/UserModify',
		dataType: 'json',
		data: JSON.stringify({
			userid: userid,
			username: username,
			pwd: pwd
		}),
		contentType: 'application/json;charset=UTF-8',
		success: function(e) {
			if (e.status === "COMMITTED") {
				window.alert('已提交执行');
			}
			window.location="<%=request.getContextPath() %>/manage/allUser.jsp";
		},
	error: function(XMLHttpRequest, textStatus, errorThrown) {
		 $("#loginBox").css("display","none");
    },
	});
}
var searchuser=function (){
	var keyword=$.trim($("#key").val());
	$.ajax({
        url:"<%=request.getContextPath()%>/ShowUserbyKeyword?keyword='"+keyword+"'",
        type:"GET",
        dataType:"json",
        success: function(data) {
            var item=data;
            var html = "<tbody id='userlist'>";
            for(var i=0;i<item.length;i++){
            	var userid=item[i].user_id;
            	var username=item[i].user_name;
            	var pwd=item[i].pwd;
                html += '<tr><td id="userid">' + item[i].user_id + '</td><td id="username">'
                        + item[i].user_name + '</td><td id="pwd">'
                        + item[i].pwd + '</td><td><a href="javascript:;" id="bLogin" onclick="ShowLoginText(\''+userid+'\',\''+username+'\',\''+pwd+'\')">编辑</a></td><td><a href="javascript:;" id="bLogin" onclick="ShowDeleteText(\''+userid+'\')" >删除</a></td></tr>';
            }
			html+="</tbody>";
            $("#userlist").replaceWith(html);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest.status);
            alert(XMLHttpRequest.readyState);
            alert(textStatus);
        },
    })	
}
window.onload=function tryapitest(){
    $.ajax({
        url:"<%=request.getContextPath()%>/ShowUser",
        type:"GET",
        dataType:"json",
        success: function(data) {
            var item=data;
            var html = "";
            for(var i=0;i<item.length;i++){
            	var userid=item[i].user_id;
            	var username=item[i].user_name;
            	var pwd=item[i].pwd;
                html += '<tr><td id="userid">' + item[i].user_id + '</td><td id="username">'
                        + item[i].user_name + '</td><td id="pwd">'
                        + item[i].pwd + '</td><td><a href="javascript:;" id="bLogin" onclick="ShowLoginText(\''+userid+'\',\''+username+'\',\''+pwd+'\')">编辑</a></td><td><a href="javascript:;" id="bLogin" onclick="ShowDeleteText(\''+userid+'\')" >删除</a></td></tr>';
            }
            $("#userlist").append(html);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest.status);
            alert(XMLHttpRequest.readyState);
            alert(textStatus);
        },
    })
}

</script>
	<body>
		<div class="sidebar sidebar-hide-to-small sidebar-shrink sidebar-gestures">
			<div class="nano">
				<div class="nano-content">
					<ul>
						<div class="logo"><a href="index.jsp"><span>教务管理系统后台</span></a></div>
						<li class="label">Main</li>
						<%
							if(request.getSession().getAttribute("identity")!=null){
								int identity=(int)request.getSession().getAttribute("identity");
								if(identity==3){
						%>
						<li><a class="sidebar-sub-toggle"><i class="ti-home"></i>用户管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
							<ul>
								<li><a href="allUser.jsp">查看所有用户</a></li>
							</ul>
						</li>
						<li><a class="sidebar-sub-toggle"><i class="ti-bar-chart-alt"></i>教师管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
							<ul>
								<li><a href="allTeacher.jsp">查看所有教师</a></li>
							</ul>
						</li>
						<li><a class="sidebar-sub-toggle"><i class="ti-home"></i>场地管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
							<ul>
								<li><a href="allPlace.jsp">查看所有场地</a></li>
							</ul>
						</li>
						<li><a class="sidebar-sub-toggle"><i class="ti-bar-chart-alt"></i>班级管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
							<ul>
								<li><a href="allClass.jsp">查看所有班级</a></li>
							</ul>
						</li><%
					}
					else{%>
						<li><a class="sidebar-sub-toggle"><i class="ti-bar-chart-alt"></i>课程管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
							<ul>
								<li><a href="allCourse.jsp">查看所有课程</a></li>
							</ul>
						</li>
						<li><a class="sidebar-sub-toggle"><i class="ti-bar-chart-alt"></i>上课管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
							<ul>
								<li><a href="allStudent.jsp">查看签到情况</a></li>
							</ul>
						</li><%
						}
					}
					else{
					%>
						<a href="<%=request.getContextPath()%>/enter">请登录</a>
						<a href="<%=request.getContextPath()%>/register">免费注册</a><%
						}
					%>

					</ul>
				</div>
			</div>
		</div>
		<div class="header">
			<div class="container-fluid">
				<div class="row">
					<div class="col-lg-12">
						<div class="dropdown dib">
							<div class="header-icon" data-toggle="dropdown">
								<span class="user-avatar"><%=request.getSession().getAttribute("userid") %>
                                    <i class="ti-angle-down f-s-10"></i>
                                </span>
								<div class="drop-down dropdown-profile dropdown-menu dropdown-menu-right">
									<div class="dropdown-content-body">
										<ul>
											<li>
												<a href="#">
													<i class="ti-settings"></i>
													<span>Setting</span>
												</a>
											</li>

											<li>
												<a href="<%=request.getContextPath() %>/exit">
													<i class="ti-power-off"></i>
													<span>Logout</span>
												</a>
											</li>
										</ul>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		</div>

		<div class="content-wrap">
			<div class="main">
				<div class="container-fluid">
					<div class="row">
						<div class="col-lg-8 p-r-0 title-margin-right">
							<div class="page-header">
								<div class="page-title">
									<h1>Hello, <span>There are all users.</span></h1>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div>
					<div class="card">
						<div class="card-title pr">
							<h4>所有查找结果</h4>
						</div>
						<div>
							<input type="text" placeholder="userid" name="key" id="key">
							<button id="btn" type="submit" onclick="searchuser()">搜索</button>
						</div>
						<div class="card-body">
							<div class="table-responsive">
								<table class="table student-data-table m-t-20">
									<thead>
										<tr>
											<th>用户ID</th>
											<th>用户姓名</th>
											<th>用户密码</th>
											<th>编辑</th>
											<th>删除</th>
										</tr>
									</thead>
									<tbody id="userlist">
									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div id="loginBox">
		<div class="login-item"><input  type="hidden" id="InputUserid"/></div>
    	<div class="login-item">用户名：<input  type="text" id="InputUsername" placeholder="用户名" /></div>
    	<div class="login-item">密码：<input  type="text" id="InputUserPwd" placeholder="密码"/></div>
    	<div class="login-item"><a href="javascript:;" onclick="usermodify()">修改</a></div>
		</div>
		<div id="deleteBox">
		<p>确定要删除该用户吗？</p>
		<div class="login-item"><input type="hidden" id="ID" /></div>
    	<div class="delete-item div-inline"><a href="javascript:;" onclick="userdelete()">确认</a></div>
    	<div class="delete-item div-inline"><a href="javascript:;" onclick="cancel()">取消</a></div>
		</div>
		<script src="assets/js/lib/jquery.min.js"></script>
	<script src="assets/js/lib/jquery.nanoscroller.min.js"></script>
	<script src="assets/js/lib/menubar/sidebar.js"></script>
	<script src="assets/js/lib/preloader/pace.min.js"></script>
	<script src="assets/js/lib/bootstrap.min.js"></script>
	<script src="assets/js/lib/circle-progress/circle-progress.min.js"></script>
	<script src="assets/js/lib/circle-progress/circle-progress-init.js"></script>
	</body>
</html>